package com.ruoyi.web.controller.student_club.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.student_club.domain.ClubActivity;
import com.ruoyi.student_club.dto.ClubAppDto;
import com.ruoyi.student_club.dto.JoinDto;
import com.ruoyi.student_club.service.IClubActivityService;
import com.ruoyi.student_club.service.IClubExamineService;
import com.ruoyi.student_club.service.IClubService;
import com.ruoyi.student_club.vo.app.ClubActivityVo;
import com.ruoyi.student_club.vo.app.ClubDetailVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lin
 * @Date 2022/1/30 0:44
 */
@RestController
@RequestMapping("/app/club")
public class ClubAppController {

    @Resource
    private IClubService clubService;

    @Resource
    private IClubActivityService activityService;

    @Resource
    private IClubExamineService examineService;

    /**
     * 获取社团详情
     * @param clubId 社团id
     * @return
     */
    @GetMapping("/getClubDetail")
    public AjaxResult clubDetail(Long clubId){
        ClubDetailVo clubDetail = clubService.getClubDetail(clubId);
        return AjaxResult.success(clubDetail);
    }

    /**
     * 获取社团活动列表
     * @param clubId 社团id
     * @return
     */
    @GetMapping("/getClubActivity")
    public AjaxResult clubActivity(Long clubId){
        List<ClubActivityVo> clubActivityList = activityService.getClubActivityList(clubId);
        return AjaxResult.success(clubActivityList);
    }

    /**
     * 获取社团活动详情
     * @param id 活动id
     * @return
     */
    @GetMapping("/getActivityDetail")
    public AjaxResult activityDetail(Long id){
        ClubActivity activityDetail = activityService.getActivityDetail(id);
        return AjaxResult.success(activityDetail);
    }

    /**
     * 获取社团列表
     * @return
     */
    @GetMapping("/getClubList")
    public AjaxResult getClubList(ClubAppDto dto){
        PageInfo pageInfo = clubService.getClubList(dto);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 申请加入社团
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public AjaxResult join(@RequestBody @Validated JoinDto dto){
        examineService.save(dto);
        return AjaxResult.success();
    }

    /**
     * 浏览数 +1
     * @return
     */
    @GetMapping("/update")
    public AjaxResult updateRead(Long clubId){
        clubService.updateRead(clubId);
        return AjaxResult.success();
    }

}
